//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

using System.Windows.Controls;
using System.Windows.Input;
using Microsoft.Research.ScientificWorkflow.ManagementStudioModels;

namespace Microsoft.Research.ScientificWorkflow.ManagementStudioControls.WorkflowManagerModule
{
    /// <summary>
    /// Interaction logic for WorkflowJobListView.xaml. This is added as a nested listview in the available workflow list. 
    /// </summary>
    public sealed partial class WorkflowJobListView : UserControl
    {
        public WorkflowJobListView()
        {
            InitializeComponent();
        }

        /// <summary>
        /// The presenter for the view.
        /// </summary>
        public object Presenter
        {
            get
            {
                return this.DataContext;
            }
            set
            {
                this.DataContext = value;
            }
        }

        /// <summary>
        /// The event handler for the context menu opening event on the listview item.
        /// </summary>
        /// <param name="sender">The source.</param>
        /// <param name="e">The event arguments.</param>
        private void ContextMenu_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        {
            e.Handled = true;
        }

        /// <summary>
        /// The event handler for the doubleclick event on the listview.
        /// </summary>
        /// <param name="sender">The source.</param>
        /// <param name="e">The event arguments.</param>
        private void DisplayListView_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            e.Handled = true;
        }


        /// <summary>
        /// The event handler for the keypress event on the listview.
        /// </summary>
        /// <param name="sender">The source.</param>
        /// <param name="e">The event arguments.</param>
        private void DisplayListView_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            // Prevent the delete pressed in the inner listview bubbling further.
            if (e.Key == Key.Delete)
            {
                e.Handled = true;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Grid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
        {
            Grid provenanceText = sender as Grid;
            JobViewModel job = provenanceText.DataContext as JobViewModel;
            (this.DataContext as WorkflowJobListPresenter).ShowProvenanceDataCommand.Execute(job);
        }
    }
}
